"""onecup URL Configuration
"""
import rest_framework
from django.urls import path, include, re_path
from django.views.generic.base import RedirectView
#from django.conf.urls import url
from django.urls import re_path as url
from public.views import Index, login4Ain
from public.viewFunc.account import myLogin, myLogout, myApply, notes, homepage
from public.viewFunc.celeryIndex import CeleryWorker, CeleryControl
from django.views.generic.base import TemplateView
from public.viewFunc import api
from rest_framework import routers
from rest_framework.documentation import include_docs_urls
from rest_framework.schemas import get_schema_view
from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPICodec
# swagger api
schema_view = get_schema_view(
    title='API 接口首页',
    renderer_classes=[SwaggerUIRenderer, OpenAPICodec],
)


router = routers.DefaultRouter()
router.register(r'user', api.UserViewSet)
router.register(r'hosts', api.HostsViewSet)
router.register(r'playbooks', api.PlaybooksViewSet)
router.register(r'ansible_tasks', api.AnsibleTasksViewSet)


class WS(TemplateView):
    template_name = 'public/websocker.html'


urlpatterns = [
    path('ansible/', include('public.urls'), ),
    path('myscheduler/', include('myscheduler.urls'), ),
    path('chatbot/', include('chatbot.urls'), ),

    path('notes/', notes),
    # re_path(r'notes/(?P<dataKey>\w+)', notes),

    # 操作 celery 相关 路径
    path('celery/node/', CeleryWorker.as_view(), {'template_file': 'public/celery_node.html'}),
    path('celery/node/<str:name>/', CeleryWorker.as_view(), {'template_file': 'public/celery_node_detail.html'}),

    # 登录，退出，注册 路径
    path('account/login', myLogin),
    path('account/logout', myLogout),
    path('account/apply', myApply),
    path('homepage/', homepage),  # 首页
    path('login4Ain/', login4Ain),  # 4A接入

    # path('ws/conn', WSConn),
    path('ws/', WS.as_view()),

    # drf 路径
    path('api/', include(router.urls), name='api'),
    path('doc_v1/', include_docs_urls(title='API 文档v1')),
    path('doc_v2/', schema_view, name='API 文档v2'),
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),

    # 处理 favicon.ico 问题
    path('favicon.ico', RedirectView.as_view(url='/static/favicon.ico')),

    path('', Index.as_view()),
    url('', include('django_prometheus.urls')),
]
